//
//  GWEmotion.m
//  新浪微博
//
//  Created by qianfeng on 16/2/20.
//  Copyright (c) 2016年 高炜. All rights reserved.
//

#import "GWEmotion.h"
#import "NSString+Emoji.h"
@implementation GWEmotion
- (NSString *)description
{
    return [NSString stringWithFormat:@"%@ - %@ - %@", self.chs, self.png, self.code];
}
-(void)setCode:(NSString *)code
{
    _code =code;
    if (code==nil) return;
   _emoji =[NSString emojiWithStringCode:code];
}

-(id)initWithCoder:(NSCoder *)aDecoder
{
    if (self =[super init]) {
        self.chs  =[aDecoder decodeObjectForKey:@"chs"];
        self.cht  =[aDecoder decodeObjectForKey:@"cht"];
        self.png  =[aDecoder decodeObjectForKey:@"png"];
        self.code  =[aDecoder decodeObjectForKey:@"code"];
        self.filePath  =[aDecoder decodeObjectForKey:@"filePath"];
        self.emoji =[aDecoder decodeObjectForKey:@"emoji"];
    }
    return self;
}
-(void)encodeWithCoder:(NSCoder *)enCoder
{
    [enCoder encodeObject:self.chs forKey:@"chs"];
    [enCoder encodeObject:self.cht forKey:@"cht"];
    [enCoder encodeObject:self.png forKey:@"png"];
    [enCoder encodeObject:self.code forKey:@"code"];
    [enCoder encodeObject:self.filePath forKey:@"filePath"];
    [enCoder encodeObject:self.emoji forKey:@"emoji"];
}
-(BOOL)isEqual:(GWEmotion *)newEmtion
{
    if (self.code) {
        return [self.code isEqualToString:newEmtion.code];
    }
    else
    {
        return [self.png isEqualToString:newEmtion.png]&&[self.chs isEqualToString:newEmtion.chs];
    }
}
@end
